package com.life.controller;

import java.util.ArrayList;

import com.life.constants.Constants;
import com.life.model.LifeModel;
import com.life.view.AbstractAdapter;

public class BoardSizeController extends AbstractController {

	AbstractAdapter applyAdapter = null;
	
	AbstractAdapter widthAdapter = null;
	AbstractAdapter heightAdapter = null;
	 
	int currentBoardWidth = Constants.START_BOARD_SIZE;
	int currentBoardHeight= Constants.START_BOARD_SIZE;
	
	public BoardSizeController(LifeModel model, ArrayList<AbstractAdapter> adapterList) {
		super(model, adapterList);
		
		applyAdapter = adapterList.get(0);
		widthAdapter = adapterList.get(1);
		heightAdapter = adapterList.get(2);
		
	}

	@Override
	public void doUpdate(AbstractAdapter source, Object data)
	{
		if(source == applyAdapter)
		{
			setBoardSize();
		}		

	}
	
	protected void setBoardSize()
	{
		int newWidth = new Integer(widthAdapter.get().toString()).intValue();
		int newHeight = new Integer(heightAdapter.get().toString()).intValue();

		if(currentBoardWidth != newWidth || currentBoardHeight != newHeight)
		{
			currentBoardWidth = newWidth;
			currentBoardHeight = newHeight;
			theModel.adjustBoardSize(currentBoardWidth,currentBoardHeight);
		}
	}
	
	

}
